package com.wanmait.movie.controller;

import com.wanmait.movie.entity.Admin;
import com.wanmait.movie.entity.Brand;
import com.wanmait.movie.entity.Comments;
import com.wanmait.movie.service.CommentsService;
import com.wanmait.movie.util.AjaxResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@RestController
@RequestMapping("manage/comments")
public class ManageCommentsController {
    @Resource
    CommentsService commentsService;

    @GetMapping("list")
    public AjaxResult list(Integer pageNum, Integer movieId, String keyword) {
        if (pageNum == null || pageNum == 0) {
            pageNum = 1;
        }
        if (movieId == null) {
            movieId = 0;
        }
        if (keyword == null) {
            keyword = "";
        }
        return AjaxResult.success(commentsService.getCommentsList(pageNum, movieId, keyword)).put("total", commentsService.getCommentsList(pageNum, movieId, keyword).getTotal());
    }
    @GetMapping("delete")
    public AjaxResult delete(Integer id){
        if(!commentsService.removeById(id)){
            return AjaxResult.error(506,"删除错误");
        }
        return AjaxResult.success(commentsService.removeById(id));
    }

}
